package com.landinfo.service.impl;

import com.landinfo.domain.UserPermission;
import com.landinfo.repository.UserPermissionRepository;
import com.landinfo.service.UserPermissionService;
import com.landinfo.service.UserService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import javax.persistence.EntityManager;
import javax.persistence.PersistenceContext;


@Service
@Transactional
public class UserPermissionServiceImpl implements UserPermissionService {
    private final Logger log = LoggerFactory.getLogger(UserService.class);

    private final UserPermissionRepository userPermissionRepository;


    @PersistenceContext
    private EntityManager entityManager;

    public UserPermissionServiceImpl(UserPermissionRepository userPermissionRepository) {
        this.userPermissionRepository = userPermissionRepository;

    }

    @Override
    public Object update(UserPermission userPermission) {
        UserPermission tempUserPermission = this.userPermissionRepository.findOneById(userPermission.getId());
        tempUserPermission.setChildren(userPermission.getChildren());
        tempUserPermission.setCode(userPermission.getCode());
        tempUserPermission.setName(userPermission.getName());
        tempUserPermission.setRemark(userPermission.getRemark());
        tempUserPermission.setSorting(userPermission.getSorting());

        return this.userPermissionRepository.save(tempUserPermission);
    }
}
